package com.school.admin.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.school.admin.common.utils.UserInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author ：sunpx
 * @date ：Created in 2021/8/17 23:02
 * @description：自动更新
 * @modified By：
 * @version: $
 */
@Component
@Slf4j
public class MetaUpdateHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.fillStrategy(metaObject, "creationTime", new Date());
        //创建人
//        this.fillStrategy(metaObject, "creatorId",  Long.valueOf(UserInfoUtil.getUserId()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.fillStrategy(metaObject, "updateTime", new Date());
        this.fillStrategy(metaObject, "reviseTime", new Date());
        this.fillStrategy(metaObject, "uptTime", new Date());
        //更新人
        this.fillStrategy(metaObject, "updateId", Long.valueOf(UserInfoUtil.getUserId()));
    }

}
